/**
 * @file rtb_assert.c
 * @author carl.pan (1586975697@qq.com)
 * @brief 
 * @version 0.1
 * @date 2025-06-29
 * 
 * @copyright Copyright (c) 2025
 * 
 */

#include "stdint.h"
#include "stddef.h"
#include "rtb_assert.h"

/* RTB_ASSERT(EX)'s hook */

void (*rtb_assert_hook)(const char *ex, const char *func, uint32_t line);

/**
 * This function will set a hook function to RTB_ASSERT(EX). It will run when the expression is false.
 *
 * @param hook the hook function
 */
void rtb_assert_set_hook(void (*hook)(const char *ex, const char *func, uint32_t line))
{
    rtb_assert_hook = hook;
}

/**
 * The RTB_ASSERT function.
 *
 * @param ex the assertion condition string
 * @param func the function name when assertion.
 * @param line the file line number when assertion.
 */
void rtb_assert_handler(const char *ex_string, const char *func, uint32_t line)
{
    volatile char dummy = 0;

    if (rtb_assert_hook == NULL)
    {
        // rtb_printf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
        while (dummy == 0)
            ;
    }
    else
    {
        rtb_assert_hook(ex_string, func, line);
    }
}
